package com.qf.day12;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class ArtShowServiceImpl implements ArtShowService{

    private List<ArtShow> data = ArtShowUtils.createList();

    public ArtShowServiceImpl() throws FileNotFoundException { //构造方法抛出异常
    }

    @Override
    public boolean addArtShow(String studentName) { //添加才艺
        ArtShow artShow = new ArtShow();
        artShow.setStuName(studentName);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入才艺名称");
        artShow.setShowName(scanner.next());
        artShow.setStatus(0);
        artShow.setCount(1);
        data.add(artShow);
        return true;
    }

    @Override
    public String pickStudent() {
        Random random = new Random(data.size());
        int i = random.nextInt();
        return data.get(i).getStuName();
    }

    @Override
    public boolean updateArtShow(ArtShow artShow) {
        for (ArtShow datum : data) { //遍历找名
            if(datum.getStuName().equals(artShow.getStuName())){
                datum.setShowName(artShow.getShowName());
                datum.setStatus(artShow.getStatus());
                datum.setCount(artShow.getCount());
                return true;
            }
        }
        return false;
    }

    @Override
    public List<ArtShow> getAll() {
        return data;
    }

    @Override
    public List<String> getNoShowNames() {
        ArrayList<String> list = new ArrayList<>();
        for (ArtShow artShow : data) {
            if (artShow.getStatus() == 0) {
                list.add(artShow.getStuName());
            }
        }
        return list;
    }
}
